package Interview;

import com.sun.org.apache.xerces.internal.impl.xpath.regex.Match;

/**
 * Created by wsy on 2017/12/2 0002.
 */
public class G1202_football {
    public static void main(String[] args) {
        int N = 40;
        int a[] = new int[N];
        initArray(a, N);
        print(a);
        System.out.println(findx(a,0,N-1, 10));

    }

    private static void initArray(int[] a, int N){
        a[0] = 3;
        for(int i = 1; i < N ; i ++){
            a[i]=a[i-1]+(Math.random()>0.3?1:-1);
        }
    }

    private static void print(int[] a){
        for (int x:a){
            System.out.print(x+" ");
        }
    }

    public static int findx(int a[], int start, int end, int x){
        int range = end - start;
        if(a[start] == x){
            return start;
        }else if((x > a[start] +range)|| (x < a[start] - range)){
            return -1;
        }else{
            return findx(a, start+Math.abs(x-a[start]), end, x);
        }
    }
}
